package by.bucha.tabnavigationproject.tabsframework;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;

public class TabListenerFromTabsFramework implements ActionBar.TabListener {

	private TabInfo mTabInfo;
	private FragmentManager mManager;

	public TabListenerFromTabsFramework(TabInfo tabInfo, FragmentManager manager) {
		mManager = manager;
		mTabInfo = tabInfo;
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		if (ft == null) {
			ft = mManager.beginTransaction();
			mTabInfo.onTabSelected(ft);
			ft.commit();
		} else {
			mTabInfo.onTabSelected(ft);
		}
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		if (ft == null) {
			ft = mManager.beginTransaction();
			mTabInfo.onTabUnselected(ft);
			ft.commit();
		} else {
			mTabInfo.onTabUnselected(ft);
		}

	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		if (ft == null) {
			ft = mManager.beginTransaction();
			mTabInfo.onTabReselected(ft);
			ft.commit();
		} else {
			mTabInfo.onTabReselected(ft);
		}
	}

}
